package bg.btanev.eightyfour.repository.impl;

import java.util.List;

import bg.btanev.eightyfour.dao.GenericDAO;
import bg.btanev.eightyfour.domain.experience.institution.EducationInstitution;
import bg.btanev.eightyfour.domain.experience.institution.Institution;
import bg.btanev.eightyfour.domain.experience.institution.WorkInstitution;
import bg.btanev.eightyfour.domain.person.ContactInfo;
import bg.btanev.eightyfour.repository.InstitutionRepository;

/**
 *
 * @author B.Tanev
 *
 */
public class InstitutionRepositoryImpl implements InstitutionRepository {
	private GenericDAO<Long, WorkInstitution> workInstitutionDAO;
	private GenericDAO<Long, EducationInstitution> educationInstitutionDAO;
	private GenericDAO<Long, Institution> institutionDAO;

	public InstitutionRepositoryImpl() {
	}

	public void setWorkInstitutionDAO(GenericDAO<Long, WorkInstitution> workInstitutionDAO) {
		this.workInstitutionDAO = workInstitutionDAO;
	}

	public void setEducationInstitutionDAO(GenericDAO<Long, EducationInstitution> educationInstitutionDAO) {
		this.educationInstitutionDAO = educationInstitutionDAO;
	}

	public void setInstitutionDAO(GenericDAO<Long, Institution> institutionDAO) {
		this.institutionDAO = institutionDAO;
	}

	@Override
	public EducationInstitution createAndStoreEducationInstitution(String name, ContactInfo contactInfo) {
		EducationInstitution educationInstitution = new EducationInstitution(name, contactInfo);
		storeInstitution(educationInstitution);
		return educationInstitution;
	}

	@Override
	public WorkInstitution createAndStoreWorkInsitution(String name, ContactInfo contactInfo) {
		WorkInstitution workInstitution = new WorkInstitution(name, contactInfo);
		storeInstitution(workInstitution);
		return workInstitution;
	}

	@Override
	public List<EducationInstitution> findAllEducationInstitutions() {
		return educationInstitutionDAO.findAll(false);
	}

	@Override
	public List<WorkInstitution> findAllWorkIntitutions() {
		return workInstitutionDAO.findAll(false);
	}

	@Override
	public List<EducationInstitution> findEducationInstitutions(String name) {
		return educationInstitutionDAO.findByPropertyName("name", name);
	}

	@Override
	public List<WorkInstitution> findWorkIntitutions(String name) {
		return workInstitutionDAO.findByPropertyName("name", name);
	}

	@Override
	public void removeInstitution(Institution institution) {
		institutionDAO.delete(institution);
	}

	@Override
	public void storeInstitution(Institution institution) {
		institutionDAO.saveUpdateEntity(institution);
	}
}
